import Mock from "mockjs";
import { MockMethod } from "vite-plugin-mock";
import utils from "../../../src/utils/utils";
import contextPath from "../../context-path";
const Random = Mock.Random;

export default [
  {
    url:
      contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/resource.listing",
    method: "post",
    response: (options) => {
      const rows: any[] = [];
      const total = 112;
      let cnt = options.body.rows;
      if (options.body.rows * options.body.page > total) {
        cnt = total - options.body.rows * (options.body.page - 1);
      }
      for (let i = 0; i < cnt; i++) {
        const template = {
          resourceId: Random.guid(),
          parentId: Random.guid(),
          levelCode: Random.natural(60, 1000),
          category: Random.string("upper", 5),
          resourceName: Random.string("upper", 5),
          resourceCode: Random.natural(60, 1000),
          uri: Random.natural(60, 1000),
          component: Random.natural(60, 1000),
          description: Random.cparagraph(2),
        };
        rows.push(template);
      }

      return {
        code: 200,
        total: total,
        rows: rows,
      };
    },
  },

  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/resource.get",
    method: "post",
    response: (options) => {
      const template = {
        resourceId: Random.guid(),
        parentId: Random.guid(),
        levelCode: Random.natural(60, 1000),
        category: Random.string("upper", 5),
        resourceName: Random.string("upper", 5),
        resourceCode: Random.natural(60, 1000),
        uri: Random.natural(60, 1000),
        component: Random.natural(60, 1000),
        path: ["res-root", "res-root-org"],
        description: Random.cparagraph(2),
      };

      return {
        code: 200,
        message: "",
        data: template,
      };
    },
  },

  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/resource.update",
    method: "post",
    response: (options) => {
      return {
        code: 200,
        message: "",
        data: null,
      };
    },
  },
  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/resource.delete",
    method: "post",
    response: (options) => {
      return {
        code: 200,
        message: "",
        data: null,
      };
    },
  },

  {
    url:
      contextPath.VITE_API_ADMIN_CONTEXT_PATH +
      "/admin/api/resource.children.listing",
    method: "post",
    response: (options) => {
      // console.log("queryCodeChildrenListing");

      const nodes: any[] = [];

      let parentId = options.body.parentId;
      if (parentId == "0") {
        let node = {
          resourceId: "res-root",
          parentId: parentId,
          levelCode: "res-root",
          category: "SYS",
          resourceName: "系统管理",
          resourceCode: "ADMIN",
          uri: "",
          component: "",
          description: Random.cparagraph(2),
          leaf: false,
          children: [],
        };
        nodes.push(node);
      }
      if (parentId == "res-root") {
        let node = {
          resourceId: "res-root-account",
          parentId: parentId,
          levelCode: "res-root-account",
          category: "SYS",
          resourceName: "账号信息管理",
          resourceCode: "ADMIN_ACCOUNT",
          uri: "/admin/account/list",
          component: "admin/account/list.vue",
          description: Random.cparagraph(2),
          leaf: true,
          children: [],
        };
        nodes.push(node);
      }
      if (parentId == "res-root") {
        let node = {
          resourceId: "res-root-org",
          parentId: parentId,
          levelCode: "res-root-org",
          category: "SYS",
          resourceName: "组织机构管理",
          resourceCode: "ADMIN_ORG",
          uri: "/admin/organization/list",
          component: "admin/organization/list.vue",
          description: Random.cparagraph(2),
          leaf: true,
          children: [],
        };
        nodes.push(node);
      }
      if (parentId == "res-root") {
        let node = {
          resourceId: "res-root-role",
          parentId: parentId,
          levelCode: "res-root-role",
          category: "SYS",
          resourceName: "角色信息管理",
          resourceCode: "ADMIN_ROLE",
          uri: "/admin/role/list",
          component: "admin/role/list.vue",
          description: Random.cparagraph(2),
          leaf: true,
          children: [],
        };
        nodes.push(node);
      }

      if (parentId == "0") {
        let node = {
          resourceId: "app-root",
          parentId: parentId,
          levelCode: "app-root",
          category: "APP",
          resourceName: "业务系统",
          resourceCode: "APP_DEMO",
          uri: "",
          component: "",
          description: Random.cparagraph(2),
          leaf: true,
          children: [],
        };
        nodes.push(node);
      }
      if (parentId == "app-root") {
        let node = {
          resourceId: "app-root-grid",
          parentId: parentId,
          levelCode: "app-root-grid",
          category: "APP",
          resourceName: "表格组件示例",
          resourceCode: "APP_GRID",
          uri: "/demo/datagrid",
          component: "demo/demo-datagrid/index.vue",
          description: Random.cparagraph(2),
          leaf: true,
          children: [],
        };
        nodes.push(node);
      }

      return {
        code: 200,
        message: "",
        data: nodes,
      };
    },
  },

  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/resource.all",
    method: "post",
    response: (options) => {
      const template = {
        resourceId: Random.guid(),
        parentId: Random.guid(),
        levelCode: Random.natural(60, 1000),
        category: Random.string("upper", 5),
        resourceName: Random.string("upper", 5),
        resourceCode: Random.natural(60, 1000),
        uri: Random.natural(60, 1000),
        component: Random.natural(60, 1000),
        path: ["res-root", "res-root-org"],
        description: Random.cparagraph(2),
        children: [],
      };

      return {
        code: 200,
        message: "",
        data: template,
      };
    },
  },
] as MockMethod[];
